package com.yaorange.service.impl;

import com.yaorange.entity.Association;
import com.yaorange.mapper.AssociationMapper;
import com.yaorange.service.AssociationService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * @Author 江就
 * @Version 1.0
 * @Date 2025/6/23
 * @Description 协会信息Service实现类
 */
@Service
public class AssociationServiceImpl implements AssociationService {

    @Resource private AssociationMapper AssociationMapper;


    /**
     * 插入协会信息
     */
    @Override
    public int save(Association association) {
        return AssociationMapper.insert(association);
    }

    /**
     * 根据主键更新协会信息
     */
    @Override
    public int modifyById(Association association) {
        return AssociationMapper.updateById(association);
    }

    /**
     * 获取单条记录
     * @return
     */
    @Override
    public Association getOne() {
        //首先尝试查询
        Association oldAssociation = AssociationMapper.selectOne(new Association());
        //如果不存在则新增一条空的新纪录
        if (ObjectUtils.isEmpty(oldAssociation)){
            Association newAssociation = new Association();
            this.save(newAssociation);
            return newAssociation;
        }
        // 存在则返回
        return oldAssociation;
    }

}
